package com.dede.getmusic.data

import org.json.JSONException
import org.json.JSONObject

/**
 * @author hsh
 * @date 2017/10/9 18:16.
 * @doc
 */
class BaseData(json: String) {
    var data: String = ""
    var code: Int = 0
    var msg: String = ""
    val status: Boolean

    init {
        var obj = JSONObject()
        try {
            obj = JSONObject(json)
        } catch (e: JSONException) {
            e.printStackTrace()
        }

        try {
            this.code = obj.getInt("code")
        } catch (e: JSONException) {
            e.printStackTrace()
        }

        this.status = code == 200

        try {
            if (obj.has("data"))
                this.data = obj.getString("data")
        } catch (e: JSONException) {
            e.printStackTrace()
        }

        try {
            if (obj.has("msg"))
                this.msg = obj.getString("msg")
        } catch (e: JSONException) {
            e.printStackTrace()
        }

    }
}